#include<iostream>
#include<memory>
#include"HandlerConnection.hpp"
#include"Listener.hpp"
#include"Reactor.hpp"
#include"PackageParse.hpp"
int main(int argc, char*argv[])
{
	if(argc!=2)
	{
		std::cerr<<"Usage:"<<argv[0]<<"local port"<<std::endl;
		exit(0);
	}
	uint16_t port =std::stoi(argv[1]);
	Listener listener(port);
	PackageParse pp;
	HandlerConnection hc(bind(&PackageParse::Execute,&pp,std::placeholders::_1));
	unique_ptr<Reactor> R = make_unique<Reactor>();
	R->SetOnConnect(bind(&Listener::Accepter,&listener,std::placeholders::_1));
	R->SetNormalHandler(
		bind(&HandlerConnection::HandlerRecver,&hc,std::placeholders::_1),
		bind(&HandlerConnection::HandlerSender,&hc,std::placeholders::_1),
		bind(&HandlerConnection::HandlerExcepter,&hc,std::placeholders::_1)
	);
	R->AddConnection(listener.Sockfd(),EPOLLIN|EPOLLET,ListenConnection);
	R->Dispatcher();
	return 0;
};